/*
 * main.c
 *
 *  Created on: Apr 25, 2014
 *      Author: Hercules
 */

#include "preProcessor.h"
#include "instructionTable.h"
#include "lexicalAnalyser.h"
#include "assembler.h"
int main(int argc, char*argv[]) {
	FILE *program_file;
	char* program_file_name;
	char* program_pre_name;
	char* program_obj_name;

	if (argc < 4) {
		printf("Faltam os nomes dos arquivos.\n");
		exit(1);
	} else {
		program_file_name = argv[1];
		program_pre_name = argv[2];
		program_obj_name = argv[3];
	}
	program_file = fopen(program_file_name, "r");
	FILE* obj_file = fopen(program_obj_name, "wb");
	if (program_file == NULL ) {
		printf("Erro ao abrir o arquivo: %s", program_file_name);
		exit(1);
	} else if (obj_file == NULL ) {
		printf("Erro ao abrir o arquivo: %s", program_obj_name);
	}
	generatePreProcessedFile(program_file, program_pre_name);
	fclose(program_file);
	program_file = fopen(program_pre_name, "r");

	SymbolTable* st = firstPass(program_file);
	rewind(program_file);

	secondPass(program_file, st, obj_file);
	fclose(obj_file);
	obj_file = fopen(program_obj_name, "rb");
	return 0;
}
